﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Reflection;

namespace QL_Truong_Hoc
{
    public partial class frmChonHocSinhDuTuyen : DevExpress.XtraEditors.XtraForm
    {
        public delegate void HocSinhSelected(int intHocSinhID);
        public event HocSinhSelected evnHocSinhSelected;

        public int TrinhDoDaoTao { get; set; }
        public int NguyenVong { get; set; }
        public int HocSinhID { get; set; }
        public bool Selected { get; set; }
        private FORM_MODE memMode;

        public enum FORM_MODE
        {
            HOC_NGHE,
            HOC_VAN_HOA,
        }

        public frmChonHocSinhDuTuyen(FORM_MODE emMode, int intTrinhDoDaoTao, int intNguyenVong)
        {
            InitializeComponent();

            this.memMode = emMode;
            this.TrinhDoDaoTao = intTrinhDoDaoTao;
            this.NguyenVong = intNguyenVong;
        }

        private void frmChonHocSinhDuTuyen_Load(object sender, EventArgs e)
        {
            //tùy vào form mode để lọc học sinh
            switch (memMode)
            {
                case FORM_MODE.HOC_NGHE:
                    //lấy học sinh đã nhập học nhưng chưa được phân lớp
                    this.tDanhSachDuTuyengetallwithdetailBindingSource.Filter = string.Format("NhapHoc = 1 And TD_ID = {0} And NG_ID <= 0", this.TrinhDoDaoTao, this.NguyenVong);

                    // TODO: This line of code loads data into the 'qLTHDataSet.tDanhSachDuTuyen_getallwithdetail' table. You can move, or remove it, as needed.
                    this.tDanhSachDuTuyen_getallwithdetailTableAdapter.Fill(this.qLTHDataSet.tDanhSachDuTuyen_getallwithdetail);

                    break;

                case FORM_MODE.HOC_VAN_HOA:
                    //lấy học sinh đã nhập học, cấp độ trung cấp và chưa được phân lớp văn hóa                    
                    this.tDanhSachDuTuyengetallwithdetailBindingSource.Filter = string.Format("NhapHoc = 1 And TD_ID = {0} And TDVH_ID < {1}", (int)clsEnum.TRINH_DO_DAO_TAO.TRUNG_CAP, (int)clsEnum.CAP_DO_VAN_HOA.LOP12);

                    // TODO: This line of code loads data into the 'qLTHDataSet.tDanhSachDuTuyen_getallwithdetail' table. You can move, or remove it, as needed.
                    this.tDanhSachDuTuyen_getallwithdetailTableAdapter.FillByLopVanHoa(this.qLTHDataSet.tDanhSachDuTuyen_getallwithdetail);

                    break;
            }

            // TODO: This line of code loads data into the 'qLTHDataSet.mDonViQuanDoi' table. You can move, or remove it, as needed.
            this.mDonViQuanDoiTableAdapter.Fill(this.qLTHDataSet.mDonViQuanDoi);
            // TODO: This line of code loads data into the 'qLTHDataSet.mNghe' table. You can move, or remove it, as needed.
            this.mNgheTableAdapter.Fill(this.qLTHDataSet.mNghe);
            // TODO: This line of code loads data into the 'qLTHDataSet.mTrinhDoDaoTao' table. You can move, or remove it, as needed.
            this.mTrinhDoDaoTaoTableAdapter.Fill(this.qLTHDataSet.mTrinhDoDaoTao);
        }

        private void btnChon_Click(object sender, EventArgs e)
        {
            try
            {
                //lấy dữ liệu
                this.HocSinhID = clsCommon.fncCnvNullToInt(dgvHocSinh.GetFocusedRowCellValue(colHS_ID));

                if (this.HocSinhID <= 0)
                {
                    clsCommon.fncMsgInfo("Hãy chọn một thí sinh.");
                    dgvHocSinh.Focus();
                    return;
                }

                this.Selected = true;
                evnHocSinhSelected(this.HocSinhID);
                dgvHocSinh.DeleteSelectedRows();
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            try
            {
                this.Selected = false;
                this.Close();
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }


    }
}